import java.util.HashMap;
import java.util.Map;

/**
 * @program: LeetCode
 * @description: LeetCode : 454. 四数相加 II
 * @author: WXY
 * @create: 2023-01-14 21:56
 * @Version 1.0
 **/
public class Num454_fourSumCount {
    public static int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num1 : nums1) {
            for (int num2 : nums2) {
                int temp = num1 + num2;
                if (map.containsKey(temp)) {
                    map.put(temp, map.get(temp) + 1);
                } else {
                    map.put(temp, 1);
                }
            }
        }
        int ans = 0;
        for (int num3 : nums3) {
            for (int num4 : nums4) {
                int temp = num3 + num4;
                if (map.containsKey(0 - temp)) {
                    ans += map.get(0 - temp);
                }
            }
        }
        return ans;
    }
}
